local fanshu = fk.CreateSkill {
  name = "lingling__fanshu",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__fanshu"] = "翻书",
  [":lingling__fanshu"] = "锁定技，游戏开始时，你随机获得两张锦囊牌并得知所有反贼的身份，然后重新调整所有角色的位置，主公至多调整至2号位。",

  ["lingling__fanshu-choose"] = "翻书：选择两名角色交换位置（主公至多调整至2号位）",

  ["$lingling__fanshu1"] = "知我罪我，其惟春秋。",
  ["$lingling__fanshu2"] = "遵古复礼，非此不足以安天下。",
}

fanshu:addEffect(fk.GameStart, {
  priority = 2,
  anim_type = "big",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fanshu.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getCardsFromPileByRule(".|.|.|.|.|trick", 2, "allPiles")
    if #ids > 0 then
      room:obtainCard(player, ids, false, fk.ReasonJustMove, player, fanshu.name)
    end
    local loop = 0
    while loop < 20 do
      local success, dat = room:askToUseActiveSkill(player, {
        skill_name = "lingling__fanshu_active",
        prompt = "lingling__fanshu-choose",
      })
      if success and dat then
        loop = loop + 1
        room:swapSeat(dat.targets[1], dat.targets[2], false)
      else
        return
      end
    end
  end,
})

fanshu:addEffect("visibility", {
  role_visible = function (self, player, target)
    if player:hasSkill(fanshu.name) and target.role == "rebel" then
      return true
    end
  end,
})

return fanshu
